install.packages("dplyr")
library(dplyr)
library(tidyverse)
library(devtools)
# install.packages("nycflights13")
library(nycflights13)
# install_github('jalapic/engsoccerdata', username = "jalapic")
library(engsoccerdata)
data(package="engsoccerdata") # lists datasets currently available
fdb = as.tbl(england)
head(fdb,10)
Date | Season | home | visitor | FT | hgoal | vgoal | division | tier | totgoal | goaldif | result |
---|---|---|---|---|---|---|---|---|---|---|---|
1888-12-15 | 1888 | Accrington F.C. | Aston Villa | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
1889-01-19 | 1888 | Accrington F.C. | Blackburn Rovers | 0-2 | 0 | 2 | 1 | 1 | 2 | -2 | A |
1889-03-23 | 1888 | Accrington F.C. | Bolton Wanderers | 2-3 | 2 | 3 | 1 | 1 | 5 | -1 | A |
1888-12-01 | 1888 | Accrington F.C. | Burnley | 5-1 | 5 | 1 | 1 | 1 | 6 | 4 | H |
1888-10-13 | 1888 | Accrington F.C. | Derby County | 6-2 | 6 | 2 | 1 | 1 | 8 | 4 | H |
1888-12-29 | 1888 | Accrington F.C. | Everton | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
1889-01-26 | 1888 | Accrington F.C. | Notts County | 1-2 | 1 | 2 | 1 | 1 | 3 | -1 | A |
1888-10-20 | 1888 | Accrington F.C. | Preston North End | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
1889-04-20 | 1888 | Accrington F.C. | Stoke City | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
1888-11-24 | 1888 | Accrington F.C. | West Bromwich Albion | 2-1 | 2 | 1 | 1 | 1 | 3 | 1 | H |
head
چند سطر بالایی یک دیتافریم را نمایش میدهد)
fdb = as.tbl(england)
head(fdb,10)
Date | Season | home | visitor | FT | hgoal | vgoal | division | tier | totgoal | goaldif | result |
---|---|---|---|---|---|---|---|---|---|---|---|
1888-12-15 | 1888 | Accrington F.C. | Aston Villa | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
1889-01-19 | 1888 | Accrington F.C. | Blackburn Rovers | 0-2 | 0 | 2 | 1 | 1 | 2 | -2 | A |
1889-03-23 | 1888 | Accrington F.C. | Bolton Wanderers | 2-3 | 2 | 3 | 1 | 1 | 5 | -1 | A |
1888-12-01 | 1888 | Accrington F.C. | Burnley | 5-1 | 5 | 1 | 1 | 1 | 6 | 4 | H |
1888-10-13 | 1888 | Accrington F.C. | Derby County | 6-2 | 6 | 2 | 1 | 1 | 8 | 4 | H |
1888-12-29 | 1888 | Accrington F.C. | Everton | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
1889-01-26 | 1888 | Accrington F.C. | Notts County | 1-2 | 1 | 2 | 1 | 1 | 3 | -1 | A |
1888-10-20 | 1888 | Accrington F.C. | Preston North End | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
1889-04-20 | 1888 | Accrington F.C. | Stoke City | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
1888-11-24 | 1888 | Accrington F.C. | West Bromwich Albion | 2-1 | 2 | 1 | 1 | 1 | 3 | 1 | H |
int
: برای اعداد صحیحdbl
: برای اعداد حقیقیchr
: برای آرایههای کاراکتری یا رشتههاdttm
: برای تاریخ-زمانها (یک date+یک time)lgl
: برای متغیرها و آرایههای منطقی که تنها مقادیر TRUE
یا FALSE
میپذیرندfctr
: فاکتورها که R از آنها برای متغیرهای دارای دستهبندی (که مقادیر مشخص از پیش تعیینشده میپذیرند) استفاده میکند.date
: برای تاریخها
filter()
انتخاب بر اساس مقدارarrange()
تغییر ترتیب ردیفهاselect()
انتخاب متغیرها بر اساس نامشانmutate()
ساختن متغیرهای جدیدی که تابعی از متغیرهای موجود هستندsummarise()
تبدیل کردن چند مقدار به یک خلاصه (summery)group_by()
استفاده شوند که میتواند محدودهٔ عملکرد هر کدام از آنها را از کل مجموعه داده (dataset) به گروهبهگروه تغییر دهد.
در مجموع این شش تابع افعال زبان دادهورزی را تشکیل میدهند.
همهٔ افعال به شکل مشابهی کار میکنند.%>%
از کتابخانهٔ magrittr
به ما این قابلیت را میدهد تا به جای استفاده کردن توابع به صورت تودرتو آنها را به صورت زنجیروار استفاده کنیم. استفاده از این عملگر برای کار با dplyr اجباری نیست با این حال به شکل واضحی خوانایی کد شما را افزایش میدهد. %>%
خروجی یک تابع را به عنوان ورودی اول به یک تابع دیگر پاس میدهد. round(sum(rnorm(20)),1)
20 %>% rnorm() %>% sum() %>% round(1)
x %>% f
معادل f(x)
x %>% f(y, .)
معادل f(y, x)
x %>% f %>% g %>% h
معادل h(g(f(x)))
x %>% f(y, z = .)
معادل f(y, z = x)
x %>% f(y = nrow(.), z = ncol(.))
معادل f(x, y = nrow(x), z = ncol(x))
.
آغاز شود؛ به عنوان خروجی یک تابع برمیگرداند که بعدا میتواند بر روی مقادیر مورد نظر ما اعمال شود.
f <- . %>% cos %>% sin
# is equivalent to
f <- function(.) sin(cos(.))
## Extract home games
fdb %>%
filter(home == "Manchester United" ) -> HManU
HManU
dim(HManU)
Date | Season | home | visitor | FT | hgoal | vgoal | division | tier | totgoal | goaldif | result |
---|---|---|---|---|---|---|---|---|---|---|---|
1893-04-08 | 1892 | Manchester United | Accrington F.C. | 3-3 | 3 | 3 | 1 | 1 | 6 | 0 | D |
1892-11-19 | 1892 | Manchester United | Aston Villa | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
1892-11-05 | 1892 | Manchester United | Blackburn Rovers | 4-4 | 4 | 4 | 1 | 1 | 8 | 0 | D |
1892-12-10 | 1892 | Manchester United | Bolton Wanderers | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
1892-09-10 | 1892 | Manchester United | Burnley | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
1892-12-31 | 1892 | Manchester United | Derby County | 7-1 | 7 | 1 | 1 | 1 | 8 | 6 | H |
1892-10-19 | 1892 | Manchester United | Everton | 3-4 | 3 | 4 | 1 | 1 | 7 | -1 | A |
1893-01-14 | 1892 | Manchester United | Nottingham Forest | 1-3 | 1 | 3 | 1 | 1 | 4 | -2 | A |
1892-11-12 | 1892 | Manchester United | Notts County | 1-3 | 1 | 3 | 1 | 1 | 4 | -2 | A |
1893-04-01 | 1892 | Manchester United | Preston North End | 2-1 | 2 | 1 | 1 | 1 | 3 | 1 | H |
1892-12-24 | 1892 | Manchester United | Sheffield Wednesday | 1-5 | 1 | 5 | 1 | 1 | 6 | -4 | A |
1893-03-31 | 1892 | Manchester United | Stoke City | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
1893-03-04 | 1892 | Manchester United | Sunderland | 0-5 | 0 | 5 | 1 | 1 | 5 | -5 | A |
1892-10-08 | 1892 | Manchester United | West Bromwich Albion | 2-4 | 2 | 4 | 1 | 1 | 6 | -2 | A |
1892-10-15 | 1892 | Manchester United | Wolverhampton Wanderers | 10-1 | 10 | 1 | 1 | 1 | 11 | 9 | H |
1893-12-16 | 1893 | Manchester United | Aston Villa | 1-3 | 1 | 3 | 1 | 1 | 4 | -2 | A |
1894-03-12 | 1893 | Manchester United | Blackburn Rovers | 5-1 | 5 | 1 | 1 | 1 | 6 | 4 | H |
1894-03-24 | 1893 | Manchester United | Bolton Wanderers | 2-2 | 2 | 2 | 1 | 1 | 4 | 0 | D |
1893-09-02 | 1893 | Manchester United | Burnley | 3-2 | 3 | 2 | 1 | 1 | 5 | 1 | H |
1893-11-04 | 1893 | Manchester United | Darwen | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
1894-03-17 | 1893 | Manchester United | Derby County | 2-6 | 2 | 6 | 1 | 1 | 8 | -4 | A |
1893-12-02 | 1893 | Manchester United | Everton | 0-3 | 0 | 3 | 1 | 1 | 3 | -3 | A |
1893-09-23 | 1893 | Manchester United | Nottingham Forest | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
1894-04-14 | 1893 | Manchester United | Preston North End | 1-3 | 1 | 3 | 1 | 1 | 4 | -2 | A |
1894-03-10 | 1893 | Manchester United | Sheffield United | 0-2 | 0 | 2 | 1 | 1 | 2 | -2 | A |
1894-01-13 | 1893 | Manchester United | Sheffield Wednesday | 1-2 | 1 | 2 | 1 | 1 | 3 | -1 | A |
1894-03-23 | 1893 | Manchester United | Stoke City | 6-2 | 6 | 2 | 1 | 1 | 8 | 4 | H |
1894-03-03 | 1893 | Manchester United | Sunderland | 2-4 | 2 | 4 | 1 | 1 | 6 | -2 | A |
1893-10-14 | 1893 | Manchester United | West Bromwich Albion | 4-1 | 4 | 1 | 1 | 1 | 5 | 3 | H |
1893-11-11 | 1893 | Manchester United | Wolverhampton Wanderers | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
2014-12-14 | 2014 | Manchester United | Liverpool | 3-0 | 3 | 0 | 1 | 1 | 3 | 3 | H |
2014-12-26 | 2014 | Manchester United | Newcastle United | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
2015-01-11 | 2014 | Manchester United | Southampton | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
2015-01-31 | 2014 | Manchester United | Leicester City | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
2015-02-11 | 2014 | Manchester United | Burnley | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
2015-02-28 | 2014 | Manchester United | Sunderland | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
2015-03-15 | 2014 | Manchester United | Tottenham Hotspur | 3-0 | 3 | 0 | 1 | 1 | 3 | 3 | H |
2015-04-04 | 2014 | Manchester United | Aston Villa | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
2015-04-12 | 2014 | Manchester United | Manchester City | 4-2 | 4 | 2 | 1 | 1 | 6 | 2 | H |
2015-05-02 | 2014 | Manchester United | West Bromwich Albion | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
2015-05-17 | 2014 | Manchester United | Arsenal | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
2015-08-08 | 2015 | Manchester United | Tottenham Hotspur | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2015-08-22 | 2015 | Manchester United | Newcastle United | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2015-09-12 | 2015 | Manchester United | Liverpool | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
2015-09-26 | 2015 | Manchester United | Sunderland | 3-0 | 3 | 0 | 1 | 1 | 3 | 3 | H |
2015-10-25 | 2015 | Manchester United | Manchester City | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2015-11-07 | 2015 | Manchester United | West Bromwich Albion | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
2015-12-05 | 2015 | Manchester United | West Ham United | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2015-12-19 | 2015 | Manchester United | Norwich City | 1-2 | 1 | 2 | 1 | 1 | 3 | -1 | A |
2015-12-28 | 2015 | Manchester United | Chelsea | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2016-01-02 | 2015 | Manchester United | Swansea City | 2-1 | 2 | 1 | 1 | 1 | 3 | 1 | H |
2016-01-23 | 2015 | Manchester United | Southampton | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
2016-02-02 | 2015 | Manchester United | Stoke City | 3-0 | 3 | 0 | 1 | 1 | 3 | 3 | H |
2016-02-28 | 2015 | Manchester United | Arsenal | 3-2 | 3 | 2 | 1 | 1 | 5 | 1 | H |
2016-03-02 | 2015 | Manchester United | Watford | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2016-04-20 | 2015 | Manchester United | Crystal Palace | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
2016-04-03 | 2015 | Manchester United | Everton | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2016-04-16 | 2015 | Manchester United | Aston Villa | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2016-05-01 | 2015 | Manchester United | Leicester City | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
2016-05-16 | 2015 | Manchester United | AFC Bournemouth | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
# Extract all records of team
fdb %>%
filter(home == "Manchester United" | visitor == "Manchester United") -> ManU
ManU
dim(ManU)
Date | Season | home | visitor | FT | hgoal | vgoal | division | tier | totgoal | goaldif | result |
---|---|---|---|---|---|---|---|---|---|---|---|
1892-11-26 | 1892 | Accrington F.C. | Manchester United | 2-2 | 2 | 2 | 1 | 1 | 4 | 0 | D |
1893-03-06 | 1892 | Aston Villa | Manchester United | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
1892-09-03 | 1892 | Blackburn Rovers | Manchester United | 4-3 | 4 | 3 | 1 | 1 | 7 | 1 | H |
1892-12-03 | 1892 | Bolton Wanderers | Manchester United | 4-1 | 4 | 1 | 1 | 1 | 5 | 3 | H |
1892-09-17 | 1892 | Burnley | Manchester United | 4-1 | 4 | 1 | 1 | 1 | 5 | 3 | H |
1893-02-11 | 1892 | Derby County | Manchester United | 5-1 | 5 | 1 | 1 | 1 | 6 | 4 | H |
1892-09-24 | 1892 | Everton | Manchester United | 6-0 | 6 | 0 | 1 | 1 | 6 | 6 | H |
1893-04-08 | 1892 | Manchester United | Accrington F.C. | 3-3 | 3 | 3 | 1 | 1 | 6 | 0 | D |
1892-11-19 | 1892 | Manchester United | Aston Villa | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
1892-11-05 | 1892 | Manchester United | Blackburn Rovers | 4-4 | 4 | 4 | 1 | 1 | 8 | 0 | D |
1892-12-10 | 1892 | Manchester United | Bolton Wanderers | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
1892-09-10 | 1892 | Manchester United | Burnley | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
1892-12-31 | 1892 | Manchester United | Derby County | 7-1 | 7 | 1 | 1 | 1 | 8 | 6 | H |
1892-10-19 | 1892 | Manchester United | Everton | 3-4 | 3 | 4 | 1 | 1 | 7 | -1 | A |
1893-01-14 | 1892 | Manchester United | Nottingham Forest | 1-3 | 1 | 3 | 1 | 1 | 4 | -2 | A |
1892-11-12 | 1892 | Manchester United | Notts County | 1-3 | 1 | 3 | 1 | 1 | 4 | -2 | A |
1893-04-01 | 1892 | Manchester United | Preston North End | 2-1 | 2 | 1 | 1 | 1 | 3 | 1 | H |
1892-12-24 | 1892 | Manchester United | Sheffield Wednesday | 1-5 | 1 | 5 | 1 | 1 | 6 | -4 | A |
1893-03-31 | 1892 | Manchester United | Stoke City | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
1893-03-04 | 1892 | Manchester United | Sunderland | 0-5 | 0 | 5 | 1 | 1 | 5 | -5 | A |
1892-10-08 | 1892 | Manchester United | West Bromwich Albion | 2-4 | 2 | 4 | 1 | 1 | 6 | -2 | A |
1892-10-15 | 1892 | Manchester United | Wolverhampton Wanderers | 10-1 | 10 | 1 | 1 | 1 | 11 | 9 | H |
1892-10-29 | 1892 | Nottingham Forest | Manchester United | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
1893-01-26 | 1892 | Notts County | Manchester United | 4-0 | 4 | 0 | 1 | 1 | 4 | 4 | H |
1892-12-26 | 1892 | Preston North End | Manchester United | 2-1 | 2 | 1 | 1 | 1 | 3 | 1 | H |
1892-10-22 | 1892 | Sheffield Wednesday | Manchester United | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
1893-01-07 | 1892 | Stoke City | Manchester United | 7-1 | 7 | 1 | 1 | 1 | 8 | 6 | H |
1893-04-04 | 1892 | Sunderland | Manchester United | 6-0 | 6 | 0 | 1 | 1 | 6 | 6 | H |
1892-10-01 | 1892 | West Bromwich Albion | Manchester United | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
1892-12-17 | 1892 | Wolverhampton Wanderers | Manchester United | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
2015-10-17 | 2015 | Everton | Manchester United | 0-3 | 0 | 3 | 1 | 1 | 3 | -3 | A |
2015-10-25 | 2015 | Manchester United | Manchester City | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2015-10-31 | 2015 | Crystal Palace | Manchester United | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2015-11-07 | 2015 | Manchester United | West Bromwich Albion | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
2015-11-21 | 2015 | Watford | Manchester United | 1-2 | 1 | 2 | 1 | 1 | 3 | -1 | A |
2015-11-28 | 2015 | Leicester City | Manchester United | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
2015-12-05 | 2015 | Manchester United | West Ham United | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2015-12-12 | 2015 | AFC Bournemouth | Manchester United | 2-1 | 2 | 1 | 1 | 1 | 3 | 1 | H |
2015-12-19 | 2015 | Manchester United | Norwich City | 1-2 | 1 | 2 | 1 | 1 | 3 | -1 | A |
2015-12-26 | 2015 | Stoke City | Manchester United | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
2015-12-28 | 2015 | Manchester United | Chelsea | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2016-01-02 | 2015 | Manchester United | Swansea City | 2-1 | 2 | 1 | 1 | 1 | 3 | 1 | H |
2016-01-12 | 2015 | Newcastle United | Manchester United | 3-3 | 3 | 3 | 1 | 1 | 6 | 0 | D |
2016-01-17 | 2015 | Liverpool | Manchester United | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
2016-01-23 | 2015 | Manchester United | Southampton | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
2016-02-02 | 2015 | Manchester United | Stoke City | 3-0 | 3 | 0 | 1 | 1 | 3 | 3 | H |
2016-02-07 | 2015 | Chelsea | Manchester United | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
2016-02-13 | 2015 | Sunderland | Manchester United | 2-1 | 2 | 1 | 1 | 1 | 3 | 1 | H |
2016-02-28 | 2015 | Manchester United | Arsenal | 3-2 | 3 | 2 | 1 | 1 | 5 | 1 | H |
2016-03-02 | 2015 | Manchester United | Watford | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2016-03-06 | 2015 | West Bromwich Albion | Manchester United | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2016-04-20 | 2015 | Manchester United | Crystal Palace | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
2016-03-20 | 2015 | Manchester City | Manchester United | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
2016-04-03 | 2015 | Manchester United | Everton | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2016-04-10 | 2015 | Tottenham Hotspur | Manchester United | 3-0 | 3 | 0 | 1 | 1 | 3 | 3 | H |
2016-04-16 | 2015 | Manchester United | Aston Villa | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2016-05-10 | 2015 | West Ham United | Manchester United | 3-2 | 3 | 2 | 1 | 1 | 5 | 1 | H |
2016-05-01 | 2015 | Manchester United | Leicester City | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
2016-05-07 | 2015 | Norwich City | Manchester United | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
2016-05-16 | 2015 | Manchester United | AFC Bournemouth | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
# Select columns with select()
ManU %>%
select(home,visitor,FT)
home | visitor | FT |
---|---|---|
Accrington F.C. | Manchester United | 2-2 |
Aston Villa | Manchester United | 2-0 |
Blackburn Rovers | Manchester United | 4-3 |
Bolton Wanderers | Manchester United | 4-1 |
Burnley | Manchester United | 4-1 |
Derby County | Manchester United | 5-1 |
Everton | Manchester United | 6-0 |
Manchester United | Accrington F.C. | 3-3 |
Manchester United | Aston Villa | 2-0 |
Manchester United | Blackburn Rovers | 4-4 |
Manchester United | Bolton Wanderers | 1-0 |
Manchester United | Burnley | 1-1 |
Manchester United | Derby County | 7-1 |
Manchester United | Everton | 3-4 |
Manchester United | Nottingham Forest | 1-3 |
Manchester United | Notts County | 1-3 |
Manchester United | Preston North End | 2-1 |
Manchester United | Sheffield Wednesday | 1-5 |
Manchester United | Stoke City | 1-0 |
Manchester United | Sunderland | 0-5 |
Manchester United | West Bromwich Albion | 2-4 |
Manchester United | Wolverhampton Wanderers | 10-1 |
Nottingham Forest | Manchester United | 1-1 |
Notts County | Manchester United | 4-0 |
Preston North End | Manchester United | 2-1 |
Sheffield Wednesday | Manchester United | 1-0 |
Stoke City | Manchester United | 7-1 |
Sunderland | Manchester United | 6-0 |
West Bromwich Albion | Manchester United | 0-0 |
Wolverhampton Wanderers | Manchester United | 2-0 |
⋮ | ⋮ | ⋮ |
Everton | Manchester United | 0-3 |
Manchester United | Manchester City | 0-0 |
Crystal Palace | Manchester United | 0-0 |
Manchester United | West Bromwich Albion | 2-0 |
Watford | Manchester United | 1-2 |
Leicester City | Manchester United | 1-1 |
Manchester United | West Ham United | 0-0 |
AFC Bournemouth | Manchester United | 2-1 |
Manchester United | Norwich City | 1-2 |
Stoke City | Manchester United | 2-0 |
Manchester United | Chelsea | 0-0 |
Manchester United | Swansea City | 2-1 |
Newcastle United | Manchester United | 3-3 |
Liverpool | Manchester United | 0-1 |
Manchester United | Southampton | 0-1 |
Manchester United | Stoke City | 3-0 |
Chelsea | Manchester United | 1-1 |
Sunderland | Manchester United | 2-1 |
Manchester United | Arsenal | 3-2 |
Manchester United | Watford | 1-0 |
West Bromwich Albion | Manchester United | 1-0 |
Manchester United | Crystal Palace | 2-0 |
Manchester City | Manchester United | 0-1 |
Manchester United | Everton | 1-0 |
Tottenham Hotspur | Manchester United | 3-0 |
Manchester United | Aston Villa | 1-0 |
West Ham United | Manchester United | 3-2 |
Manchester United | Leicester City | 1-1 |
Norwich City | Manchester United | 0-1 |
Manchester United | AFC Bournemouth | 3-1 |
# Select sequence of columns
ManU %>%
select(Date:FT)
Date | Season | home | visitor | FT |
---|---|---|---|---|
1892-11-26 | 1892 | Accrington F.C. | Manchester United | 2-2 |
1893-03-06 | 1892 | Aston Villa | Manchester United | 2-0 |
1892-09-03 | 1892 | Blackburn Rovers | Manchester United | 4-3 |
1892-12-03 | 1892 | Bolton Wanderers | Manchester United | 4-1 |
1892-09-17 | 1892 | Burnley | Manchester United | 4-1 |
1893-02-11 | 1892 | Derby County | Manchester United | 5-1 |
1892-09-24 | 1892 | Everton | Manchester United | 6-0 |
1893-04-08 | 1892 | Manchester United | Accrington F.C. | 3-3 |
1892-11-19 | 1892 | Manchester United | Aston Villa | 2-0 |
1892-11-05 | 1892 | Manchester United | Blackburn Rovers | 4-4 |
1892-12-10 | 1892 | Manchester United | Bolton Wanderers | 1-0 |
1892-09-10 | 1892 | Manchester United | Burnley | 1-1 |
1892-12-31 | 1892 | Manchester United | Derby County | 7-1 |
1892-10-19 | 1892 | Manchester United | Everton | 3-4 |
1893-01-14 | 1892 | Manchester United | Nottingham Forest | 1-3 |
1892-11-12 | 1892 | Manchester United | Notts County | 1-3 |
1893-04-01 | 1892 | Manchester United | Preston North End | 2-1 |
1892-12-24 | 1892 | Manchester United | Sheffield Wednesday | 1-5 |
1893-03-31 | 1892 | Manchester United | Stoke City | 1-0 |
1893-03-04 | 1892 | Manchester United | Sunderland | 0-5 |
1892-10-08 | 1892 | Manchester United | West Bromwich Albion | 2-4 |
1892-10-15 | 1892 | Manchester United | Wolverhampton Wanderers | 10-1 |
1892-10-29 | 1892 | Nottingham Forest | Manchester United | 1-1 |
1893-01-26 | 1892 | Notts County | Manchester United | 4-0 |
1892-12-26 | 1892 | Preston North End | Manchester United | 2-1 |
1892-10-22 | 1892 | Sheffield Wednesday | Manchester United | 1-0 |
1893-01-07 | 1892 | Stoke City | Manchester United | 7-1 |
1893-04-04 | 1892 | Sunderland | Manchester United | 6-0 |
1892-10-01 | 1892 | West Bromwich Albion | Manchester United | 0-0 |
1892-12-17 | 1892 | Wolverhampton Wanderers | Manchester United | 2-0 |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
2015-10-17 | 2015 | Everton | Manchester United | 0-3 |
2015-10-25 | 2015 | Manchester United | Manchester City | 0-0 |
2015-10-31 | 2015 | Crystal Palace | Manchester United | 0-0 |
2015-11-07 | 2015 | Manchester United | West Bromwich Albion | 2-0 |
2015-11-21 | 2015 | Watford | Manchester United | 1-2 |
2015-11-28 | 2015 | Leicester City | Manchester United | 1-1 |
2015-12-05 | 2015 | Manchester United | West Ham United | 0-0 |
2015-12-12 | 2015 | AFC Bournemouth | Manchester United | 2-1 |
2015-12-19 | 2015 | Manchester United | Norwich City | 1-2 |
2015-12-26 | 2015 | Stoke City | Manchester United | 2-0 |
2015-12-28 | 2015 | Manchester United | Chelsea | 0-0 |
2016-01-02 | 2015 | Manchester United | Swansea City | 2-1 |
2016-01-12 | 2015 | Newcastle United | Manchester United | 3-3 |
2016-01-17 | 2015 | Liverpool | Manchester United | 0-1 |
2016-01-23 | 2015 | Manchester United | Southampton | 0-1 |
2016-02-02 | 2015 | Manchester United | Stoke City | 3-0 |
2016-02-07 | 2015 | Chelsea | Manchester United | 1-1 |
2016-02-13 | 2015 | Sunderland | Manchester United | 2-1 |
2016-02-28 | 2015 | Manchester United | Arsenal | 3-2 |
2016-03-02 | 2015 | Manchester United | Watford | 1-0 |
2016-03-06 | 2015 | West Bromwich Albion | Manchester United | 1-0 |
2016-04-20 | 2015 | Manchester United | Crystal Palace | 2-0 |
2016-03-20 | 2015 | Manchester City | Manchester United | 0-1 |
2016-04-03 | 2015 | Manchester United | Everton | 1-0 |
2016-04-10 | 2015 | Tottenham Hotspur | Manchester United | 3-0 |
2016-04-16 | 2015 | Manchester United | Aston Villa | 1-0 |
2016-05-10 | 2015 | West Ham United | Manchester United | 3-2 |
2016-05-01 | 2015 | Manchester United | Leicester City | 1-1 |
2016-05-07 | 2015 | Norwich City | Manchester United | 0-1 |
2016-05-16 | 2015 | Manchester United | AFC Bournemouth | 3-1 |
rbind
دو دیتافریم را بر اساس ردیفهای آن ادغام میکند.) به نحوهٔ استفاده از تابع summarise توجه کنید.
# Find Game Winning Numbers
# Home wins
ManU %>% filter(home == "Manchester United") %>%
select(team = home, opp = visitor,Season, MG = hgoal,OG = vgoal) -> hw
# Visitors wins
ManU %>% filter(visitor == "Manchester United") %>%
select(team = visitor, opp = home,Season, Season, MG = vgoal,OG = hgoal) -> vw
wman = rbind(hw,vw) # bind home and visitors wins
head(wman,2)
# Total result summary
wman %>% summarise(Win = sum(MG > OG),Equal = sum(MG == OG),Loose = sum(MG < OG))
team | opp | Season | MG | OG |
---|---|---|---|---|
Manchester United | Accrington F.C. | 1892 | 3 | 3 |
Manchester United | Aston Villa | 1892 | 2 | 0 |
Win | Equal | Loose |
---|---|---|
2154 | 1066 | 1260 |
desc()
برای مرتب کردن یک ستون به صورت نزولی به کار میرود
# Ten high-scoring football match!
ManU %>%
arrange(desc(totgoal)) %>%
slice(1:10)
Date | Season | home | visitor | FT | hgoal | vgoal | division | tier | totgoal | goaldif | result |
---|---|---|---|---|---|---|---|---|---|---|---|
1892-10-15 | 1892 | Manchester United | Wolverhampton Wanderers | 10-1 | 10 | 1 | 1 | 1 | 11 | 9 | H |
1908-03-25 | 1907 | Liverpool | Manchester United | 7-4 | 7 | 4 | 1 | 1 | 11 | 3 | H |
1930-09-13 | 1930 | Manchester United | Newcastle United | 4-7 | 4 | 7 | 1 | 1 | 11 | -3 | A |
1954-10-16 | 1954 | Chelsea | Manchester United | 5-6 | 5 | 6 | 1 | 1 | 11 | -1 | A |
1895-11-16 | 1895 | Manchester United | Lincoln City | 5-5 | 5 | 5 | 2 | 2 | 10 | 0 | D |
1933-12-26 | 1933 | Grimsby Town | Manchester United | 7-3 | 7 | 3 | 2 | 2 | 10 | 4 | H |
1960-01-02 | 1959 | Newcastle United | Manchester United | 7-3 | 7 | 3 | 1 | 1 | 10 | 4 | H |
2011-08-28 | 2011 | Manchester United | Arsenal | 8-2 | 8 | 2 | 1 | 1 | 10 | 6 | H |
2013-05-19 | 2012 | West Bromwich Albion | Manchester United | 5-5 | 5 | 5 | 1 | 1 | 10 | 0 | D |
1895-04-03 | 1894 | Manchester United | Walsall | 9-0 | 9 | 0 | 2 | 2 | 9 | 9 | H |
# The Top 10 Biggest Home Wins
ManU %>%
filter(home == "Manchester United") %>%
arrange(desc(hgoal),vgoal) %>%
slice(1:10)
Date | Season | home | visitor | FT | hgoal | vgoal | division | tier | totgoal | goaldif | result |
---|---|---|---|---|---|---|---|---|---|---|---|
1892-10-15 | 1892 | Manchester United | Wolverhampton Wanderers | 10-1 | 10 | 1 | 1 | 1 | 11 | 9 | H |
1895-04-03 | 1894 | Manchester United | Walsall | 9-0 | 9 | 0 | 2 | 2 | 9 | 9 | H |
1898-12-24 | 1898 | Manchester United | Darwen | 9-0 | 9 | 0 | 2 | 2 | 9 | 9 | H |
1995-03-04 | 1994 | Manchester United | Ipswich Town | 9-0 | 9 | 0 | 1 | 1 | 9 | 9 | H |
1969-03-19 | 1968 | Manchester United | Queens Park Rangers | 8-1 | 8 | 1 | 1 | 1 | 9 | 7 | H |
2011-08-28 | 2011 | Manchester United | Arsenal | 8-2 | 8 | 2 | 1 | 1 | 10 | 6 | H |
1905-01-02 | 1904 | Manchester United | Bradford City | 7-0 | 7 | 0 | 2 | 2 | 7 | 7 | H |
1950-03-08 | 1949 | Manchester United | Aston Villa | 7-0 | 7 | 0 | 1 | 1 | 7 | 7 | H |
1964-10-24 | 1964 | Manchester United | Aston Villa | 7-0 | 7 | 0 | 1 | 1 | 7 | 7 | H |
1970-04-08 | 1969 | Manchester United | West Bromwich Albion | 7-0 | 7 | 0 | 1 | 1 | 7 | 7 | H |
# Extract distinct Teams
ManU %>%
filter(home == "Manchester United") %>%
select(visitor) %>%
distinct()
visitor |
---|
Accrington F.C. |
Aston Villa |
Blackburn Rovers |
Bolton Wanderers |
Burnley |
Derby County |
Everton |
Nottingham Forest |
Notts County |
Preston North End |
Sheffield Wednesday |
Stoke City |
Sunderland |
West Bromwich Albion |
Wolverhampton Wanderers |
Darwen |
Sheffield United |
Arsenal |
Burton Swifts |
Burton Wanderers |
Bury |
Crewe Alexandra |
Grimsby Town |
Leicester City |
Lincoln City |
Manchester City |
Newcastle United |
Port Vale |
Rotherham Town |
Walsall |
⋮ |
Cardiff City |
Coventry City |
Crystal Palace |
Fulham |
Leeds United |
Rotherham County |
South Shields |
Southampton |
West Ham United |
Nelson |
Portsmouth |
Charlton Athletic |
Millwall |
Plymouth Argyle |
Swansea City |
Brentford |
Norwich City |
Ipswich Town |
Northampton Town |
Queens Park Rangers |
Bristol Rovers |
Oxford United |
York City |
Brighton & Hove Albion |
Watford |
Wimbledon |
Swindon Town |
Wigan Athletic |
Reading |
AFC Bournemouth |
# Extract distinct Games
ManU %>%
select(home, visitor) %>%
distinct()
home | visitor |
---|---|
Accrington F.C. | Manchester United |
Aston Villa | Manchester United |
Blackburn Rovers | Manchester United |
Bolton Wanderers | Manchester United |
Burnley | Manchester United |
Derby County | Manchester United |
Everton | Manchester United |
Manchester United | Accrington F.C. |
Manchester United | Aston Villa |
Manchester United | Blackburn Rovers |
Manchester United | Bolton Wanderers |
Manchester United | Burnley |
Manchester United | Derby County |
Manchester United | Everton |
Manchester United | Nottingham Forest |
Manchester United | Notts County |
Manchester United | Preston North End |
Manchester United | Sheffield Wednesday |
Manchester United | Stoke City |
Manchester United | Sunderland |
Manchester United | West Bromwich Albion |
Manchester United | Wolverhampton Wanderers |
Nottingham Forest | Manchester United |
Notts County | Manchester United |
Preston North End | Manchester United |
Sheffield Wednesday | Manchester United |
Stoke City | Manchester United |
Sunderland | Manchester United |
West Bromwich Albion | Manchester United |
Wolverhampton Wanderers | Manchester United |
⋮ | ⋮ |
Brentford | Manchester United |
Manchester United | Brentford |
Manchester United | Norwich City |
Norwich City | Manchester United |
Ipswich Town | Manchester United |
Manchester United | Ipswich Town |
Manchester United | Northampton Town |
Northampton Town | Manchester United |
Manchester United | Queens Park Rangers |
Queens Park Rangers | Manchester United |
Bristol Rovers | Manchester United |
Manchester United | Bristol Rovers |
Manchester United | Oxford United |
Manchester United | York City |
Oxford United | Manchester United |
York City | Manchester United |
Brighton & Hove Albion | Manchester United |
Manchester United | Brighton & Hove Albion |
Manchester United | Watford |
Watford | Manchester United |
Manchester United | Wimbledon |
Wimbledon | Manchester United |
Manchester United | Swindon Town |
Swindon Town | Manchester United |
Manchester United | Wigan Athletic |
Wigan Athletic | Manchester United |
Manchester United | Reading |
Reading | Manchester United |
AFC Bournemouth | Manchester United |
Manchester United | AFC Bournemouth |
# Add column
ManU %>%
mutate(gain = goaldif / totgoal) %>%
select(gain,goaldif,totgoal)
gain | goaldif | totgoal |
---|---|---|
0.0000000 | 0 | 4 |
1.0000000 | 2 | 2 |
0.1428571 | 1 | 7 |
0.6000000 | 3 | 5 |
0.6000000 | 3 | 5 |
0.6666667 | 4 | 6 |
1.0000000 | 6 | 6 |
0.0000000 | 0 | 6 |
1.0000000 | 2 | 2 |
0.0000000 | 0 | 8 |
1.0000000 | 1 | 1 |
0.0000000 | 0 | 2 |
0.7500000 | 6 | 8 |
-0.1428571 | -1 | 7 |
-0.5000000 | -2 | 4 |
-0.5000000 | -2 | 4 |
0.3333333 | 1 | 3 |
-0.6666667 | -4 | 6 |
1.0000000 | 1 | 1 |
-1.0000000 | -5 | 5 |
-0.3333333 | -2 | 6 |
0.8181818 | 9 | 11 |
0.0000000 | 0 | 2 |
1.0000000 | 4 | 4 |
0.3333333 | 1 | 3 |
1.0000000 | 1 | 1 |
0.7500000 | 6 | 8 |
1.0000000 | 6 | 6 |
NaN | 0 | 0 |
1.0000000 | 2 | 2 |
⋮ | ⋮ | ⋮ |
-1.0000000 | -3 | 3 |
NaN | 0 | 0 |
NaN | 0 | 0 |
1.0000000 | 2 | 2 |
-0.3333333 | -1 | 3 |
0.0000000 | 0 | 2 |
NaN | 0 | 0 |
0.3333333 | 1 | 3 |
-0.3333333 | -1 | 3 |
1.0000000 | 2 | 2 |
NaN | 0 | 0 |
0.3333333 | 1 | 3 |
0.0000000 | 0 | 6 |
-1.0000000 | -1 | 1 |
-1.0000000 | -1 | 1 |
1.0000000 | 3 | 3 |
0.0000000 | 0 | 2 |
0.3333333 | 1 | 3 |
0.2000000 | 1 | 5 |
1.0000000 | 1 | 1 |
1.0000000 | 1 | 1 |
1.0000000 | 2 | 2 |
-1.0000000 | -1 | 1 |
1.0000000 | 1 | 1 |
1.0000000 | 3 | 3 |
1.0000000 | 1 | 1 |
0.2000000 | 1 | 5 |
0.0000000 | 0 | 2 |
-1.0000000 | -1 | 1 |
0.5000000 | 2 | 4 |
# Randomly sample games by number
ManU %>%
sample_n(2)
ManU %>%
sample_frac(0.01) %>%
head(2)
Date | Season | home | visitor | FT | hgoal | vgoal | division | tier | totgoal | goaldif | result |
---|---|---|---|---|---|---|---|---|---|---|---|
1966-09-24 | 1966 | Manchester United | Burnley | 4-1 | 4 | 1 | 1 | 1 | 5 | 3 | H |
2010-09-26 | 2010 | Bolton Wanderers | Manchester United | 2-2 | 2 | 2 | 1 | 1 | 4 | 0 | D |
Date | Season | home | visitor | FT | hgoal | vgoal | division | tier | totgoal | goaldif | result |
---|---|---|---|---|---|---|---|---|---|---|---|
1911-03-04 | 1910 | Middlesbrough | Manchester United | 2-2 | 2 | 2 | 1 | 1 | 4 | 0 | D |
1932-03-05 | 1931 | Notts County | Manchester United | 1-2 | 1 | 2 | 2 | 2 | 3 | -1 | A |
# Group a data by one or more variable
ManU %>%
filter(home == "Manchester United") %>%
group_by(Season,tier) -> mang
mang
Date | Season | home | visitor | FT | hgoal | vgoal | division | tier | totgoal | goaldif | result |
---|---|---|---|---|---|---|---|---|---|---|---|
1893-04-08 | 1892 | Manchester United | Accrington F.C. | 3-3 | 3 | 3 | 1 | 1 | 6 | 0 | D |
1892-11-19 | 1892 | Manchester United | Aston Villa | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
1892-11-05 | 1892 | Manchester United | Blackburn Rovers | 4-4 | 4 | 4 | 1 | 1 | 8 | 0 | D |
1892-12-10 | 1892 | Manchester United | Bolton Wanderers | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
1892-09-10 | 1892 | Manchester United | Burnley | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
1892-12-31 | 1892 | Manchester United | Derby County | 7-1 | 7 | 1 | 1 | 1 | 8 | 6 | H |
1892-10-19 | 1892 | Manchester United | Everton | 3-4 | 3 | 4 | 1 | 1 | 7 | -1 | A |
1893-01-14 | 1892 | Manchester United | Nottingham Forest | 1-3 | 1 | 3 | 1 | 1 | 4 | -2 | A |
1892-11-12 | 1892 | Manchester United | Notts County | 1-3 | 1 | 3 | 1 | 1 | 4 | -2 | A |
1893-04-01 | 1892 | Manchester United | Preston North End | 2-1 | 2 | 1 | 1 | 1 | 3 | 1 | H |
1892-12-24 | 1892 | Manchester United | Sheffield Wednesday | 1-5 | 1 | 5 | 1 | 1 | 6 | -4 | A |
1893-03-31 | 1892 | Manchester United | Stoke City | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
1893-03-04 | 1892 | Manchester United | Sunderland | 0-5 | 0 | 5 | 1 | 1 | 5 | -5 | A |
1892-10-08 | 1892 | Manchester United | West Bromwich Albion | 2-4 | 2 | 4 | 1 | 1 | 6 | -2 | A |
1892-10-15 | 1892 | Manchester United | Wolverhampton Wanderers | 10-1 | 10 | 1 | 1 | 1 | 11 | 9 | H |
1893-12-16 | 1893 | Manchester United | Aston Villa | 1-3 | 1 | 3 | 1 | 1 | 4 | -2 | A |
1894-03-12 | 1893 | Manchester United | Blackburn Rovers | 5-1 | 5 | 1 | 1 | 1 | 6 | 4 | H |
1894-03-24 | 1893 | Manchester United | Bolton Wanderers | 2-2 | 2 | 2 | 1 | 1 | 4 | 0 | D |
1893-09-02 | 1893 | Manchester United | Burnley | 3-2 | 3 | 2 | 1 | 1 | 5 | 1 | H |
1893-11-04 | 1893 | Manchester United | Darwen | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
1894-03-17 | 1893 | Manchester United | Derby County | 2-6 | 2 | 6 | 1 | 1 | 8 | -4 | A |
1893-12-02 | 1893 | Manchester United | Everton | 0-3 | 0 | 3 | 1 | 1 | 3 | -3 | A |
1893-09-23 | 1893 | Manchester United | Nottingham Forest | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
1894-04-14 | 1893 | Manchester United | Preston North End | 1-3 | 1 | 3 | 1 | 1 | 4 | -2 | A |
1894-03-10 | 1893 | Manchester United | Sheffield United | 0-2 | 0 | 2 | 1 | 1 | 2 | -2 | A |
1894-01-13 | 1893 | Manchester United | Sheffield Wednesday | 1-2 | 1 | 2 | 1 | 1 | 3 | -1 | A |
1894-03-23 | 1893 | Manchester United | Stoke City | 6-2 | 6 | 2 | 1 | 1 | 8 | 4 | H |
1894-03-03 | 1893 | Manchester United | Sunderland | 2-4 | 2 | 4 | 1 | 1 | 6 | -2 | A |
1893-10-14 | 1893 | Manchester United | West Bromwich Albion | 4-1 | 4 | 1 | 1 | 1 | 5 | 3 | H |
1893-11-11 | 1893 | Manchester United | Wolverhampton Wanderers | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
2014-12-14 | 2014 | Manchester United | Liverpool | 3-0 | 3 | 0 | 1 | 1 | 3 | 3 | H |
2014-12-26 | 2014 | Manchester United | Newcastle United | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
2015-01-11 | 2014 | Manchester United | Southampton | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
2015-01-31 | 2014 | Manchester United | Leicester City | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
2015-02-11 | 2014 | Manchester United | Burnley | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
2015-02-28 | 2014 | Manchester United | Sunderland | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
2015-03-15 | 2014 | Manchester United | Tottenham Hotspur | 3-0 | 3 | 0 | 1 | 1 | 3 | 3 | H |
2015-04-04 | 2014 | Manchester United | Aston Villa | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
2015-04-12 | 2014 | Manchester United | Manchester City | 4-2 | 4 | 2 | 1 | 1 | 6 | 2 | H |
2015-05-02 | 2014 | Manchester United | West Bromwich Albion | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
2015-05-17 | 2014 | Manchester United | Arsenal | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
2015-08-08 | 2015 | Manchester United | Tottenham Hotspur | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2015-08-22 | 2015 | Manchester United | Newcastle United | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2015-09-12 | 2015 | Manchester United | Liverpool | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
2015-09-26 | 2015 | Manchester United | Sunderland | 3-0 | 3 | 0 | 1 | 1 | 3 | 3 | H |
2015-10-25 | 2015 | Manchester United | Manchester City | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2015-11-07 | 2015 | Manchester United | West Bromwich Albion | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
2015-12-05 | 2015 | Manchester United | West Ham United | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2015-12-19 | 2015 | Manchester United | Norwich City | 1-2 | 1 | 2 | 1 | 1 | 3 | -1 | A |
2015-12-28 | 2015 | Manchester United | Chelsea | 0-0 | 0 | 0 | 1 | 1 | 0 | 0 | D |
2016-01-02 | 2015 | Manchester United | Swansea City | 2-1 | 2 | 1 | 1 | 1 | 3 | 1 | H |
2016-01-23 | 2015 | Manchester United | Southampton | 0-1 | 0 | 1 | 1 | 1 | 1 | -1 | A |
2016-02-02 | 2015 | Manchester United | Stoke City | 3-0 | 3 | 0 | 1 | 1 | 3 | 3 | H |
2016-02-28 | 2015 | Manchester United | Arsenal | 3-2 | 3 | 2 | 1 | 1 | 5 | 1 | H |
2016-03-02 | 2015 | Manchester United | Watford | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2016-04-20 | 2015 | Manchester United | Crystal Palace | 2-0 | 2 | 0 | 1 | 1 | 2 | 2 | H |
2016-04-03 | 2015 | Manchester United | Everton | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2016-04-16 | 2015 | Manchester United | Aston Villa | 1-0 | 1 | 0 | 1 | 1 | 1 | 1 | H |
2016-05-01 | 2015 | Manchester United | Leicester City | 1-1 | 1 | 1 | 1 | 1 | 2 | 0 | D |
2016-05-16 | 2015 | Manchester United | AFC Bournemouth | 3-1 | 3 | 1 | 1 | 1 | 4 | 2 | H |
# make summary table
mang %>%
summarise(
HAG = round(mean(hgoal),2),
HTG = sum(hgoal),
HW = sum(result == "H")) -> Hstat
Hstat
Season | tier | HAG | HTG | HW |
---|---|---|---|---|
1892 | 1 | 2.60 | 39 | 6 |
1893 | 1 | 1.93 | 29 | 5 |
1894 | 2 | 3.47 | 52 | 9 |
1895 | 2 | 3.20 | 48 | 12 |
1896 | 2 | 2.47 | 37 | 11 |
1897 | 2 | 2.80 | 42 | 11 |
1898 | 2 | 3.00 | 51 | 12 |
1899 | 2 | 2.59 | 44 | 15 |
1900 | 2 | 1.82 | 31 | 11 |
1901 | 2 | 1.59 | 27 | 10 |
1902 | 2 | 1.88 | 32 | 9 |
1903 | 2 | 2.47 | 42 | 14 |
1904 | 2 | 3.53 | 60 | 16 |
1905 | 2 | 2.89 | 55 | 15 |
1906 | 1 | 1.74 | 33 | 10 |
1907 | 1 | 2.26 | 43 | 15 |
1908 | 1 | 1.95 | 37 | 10 |
1909 | 1 | 2.16 | 41 | 14 |
1910 | 1 | 2.47 | 47 | 14 |
1911 | 1 | 1.53 | 29 | 9 |
1912 | 1 | 2.16 | 41 | 13 |
1913 | 1 | 1.42 | 27 | 8 |
1914 | 1 | 1.42 | 27 | 8 |
1919 | 1 | 0.95 | 20 | 6 |
1920 | 1 | 1.62 | 34 | 9 |
1921 | 1 | 1.19 | 25 | 7 |
1922 | 2 | 1.19 | 25 | 10 |
1923 | 2 | 1.76 | 37 | 10 |
1924 | 2 | 1.90 | 40 | 17 |
1925 | 1 | 1.90 | 40 | 12 |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
1986 | 1 | 1.81 | 38 | 13 |
1987 | 1 | 2.05 | 41 | 14 |
1988 | 1 | 1.42 | 27 | 10 |
1989 | 1 | 1.37 | 26 | 8 |
1990 | 1 | 1.79 | 34 | 11 |
1991 | 1 | 1.62 | 34 | 12 |
1992 | 1 | 1.86 | 39 | 14 |
1993 | 1 | 1.86 | 39 | 14 |
1994 | 1 | 2.00 | 42 | 16 |
1995 | 1 | 1.89 | 36 | 15 |
1996 | 1 | 2.00 | 38 | 12 |
1997 | 1 | 2.21 | 42 | 13 |
1998 | 1 | 2.37 | 45 | 14 |
1999 | 1 | 3.11 | 59 | 15 |
2000 | 1 | 2.58 | 49 | 15 |
2001 | 1 | 2.11 | 40 | 11 |
2002 | 1 | 2.21 | 42 | 16 |
2003 | 1 | 1.95 | 37 | 12 |
2004 | 1 | 1.63 | 31 | 12 |
2005 | 1 | 1.95 | 37 | 13 |
2006 | 1 | 2.42 | 46 | 15 |
2007 | 1 | 2.47 | 47 | 17 |
2008 | 1 | 2.26 | 43 | 16 |
2009 | 1 | 2.74 | 52 | 16 |
2010 | 1 | 2.58 | 49 | 18 |
2011 | 1 | 2.74 | 52 | 15 |
2012 | 1 | 2.37 | 45 | 16 |
2013 | 1 | 1.53 | 29 | 9 |
2014 | 1 | 2.16 | 41 | 14 |
2015 | 1 | 1.42 | 27 | 12 |
# Table of Manchester United results
ManU %>%
filter(visitor == "Manchester United") %>%
group_by(Season,tier) %>%
summarise(
VAG = round(mean(hgoal),2),
VTG = sum(hgoal),
VW = sum(result == "H")) -> VStat
full_join(Hstat,VStat)
Joining, by = c("Season", "tier")
Season | tier | HAG | HTG | HW | VAG | VTG | VW |
---|---|---|---|---|---|---|---|
1892 | 1 | 2.60 | 39 | 6 | 3.33 | 50 | 12 |
1893 | 1 | 1.93 | 29 | 5 | 2.60 | 39 | 14 |
1894 | 2 | 3.47 | 52 | 9 | 1.73 | 26 | 7 |
1895 | 2 | 3.20 | 48 | 12 | 2.80 | 42 | 11 |
1896 | 2 | 2.47 | 37 | 11 | 1.60 | 24 | 8 |
1897 | 2 | 2.80 | 42 | 11 | 1.67 | 25 | 6 |
1898 | 2 | 3.00 | 51 | 12 | 1.71 | 29 | 9 |
1899 | 2 | 2.59 | 44 | 15 | 0.94 | 16 | 9 |
1900 | 2 | 1.82 | 31 | 11 | 1.71 | 29 | 13 |
1901 | 2 | 1.59 | 27 | 10 | 2.41 | 41 | 12 |
1902 | 2 | 1.88 | 32 | 9 | 1.35 | 23 | 7 |
1903 | 2 | 2.47 | 42 | 14 | 1.12 | 19 | 5 |
1904 | 2 | 3.53 | 60 | 16 | 1.18 | 20 | 4 |
1905 | 2 | 2.89 | 55 | 15 | 0.79 | 15 | 3 |
1906 | 1 | 1.74 | 33 | 10 | 2.16 | 41 | 10 |
1907 | 1 | 2.26 | 43 | 15 | 1.53 | 29 | 6 |
1908 | 1 | 1.95 | 37 | 10 | 1.84 | 35 | 10 |
1909 | 1 | 2.16 | 41 | 14 | 2.16 | 41 | 9 |
1910 | 1 | 2.47 | 47 | 14 | 1.16 | 22 | 7 |
1911 | 1 | 1.53 | 29 | 9 | 2.16 | 41 | 9 |
1912 | 1 | 2.16 | 41 | 13 | 1.53 | 29 | 8 |
1913 | 1 | 1.42 | 27 | 8 | 2.05 | 39 | 10 |
1914 | 1 | 1.42 | 27 | 8 | 2.26 | 43 | 12 |
1919 | 1 | 0.95 | 20 | 6 | 1.57 | 33 | 8 |
1920 | 1 | 1.62 | 34 | 9 | 2.00 | 42 | 9 |
1921 | 1 | 1.19 | 25 | 7 | 2.24 | 47 | 15 |
1922 | 2 | 1.19 | 25 | 10 | 0.90 | 19 | 6 |
1923 | 2 | 1.76 | 37 | 10 | 1.38 | 29 | 11 |
1924 | 2 | 1.90 | 40 | 17 | 0.81 | 17 | 7 |
1925 | 1 | 1.90 | 40 | 12 | 2.24 | 47 | 12 |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
1986 | 1 | 1.81 | 38 | 13 | 1.29 | 27 | 9 |
1987 | 1 | 2.05 | 41 | 14 | 1.05 | 21 | 4 |
1988 | 1 | 1.42 | 27 | 10 | 1.16 | 22 | 9 |
1989 | 1 | 1.37 | 26 | 8 | 1.74 | 33 | 11 |
1990 | 1 | 1.79 | 34 | 11 | 1.47 | 28 | 6 |
1991 | 1 | 1.62 | 34 | 12 | 0.95 | 20 | 4 |
1992 | 1 | 1.86 | 39 | 14 | 0.81 | 17 | 4 |
1993 | 1 | 1.86 | 39 | 14 | 1.19 | 25 | 3 |
1994 | 1 | 2.00 | 42 | 16 | 1.14 | 24 | 5 |
1995 | 1 | 1.89 | 36 | 15 | 1.37 | 26 | 6 |
1996 | 1 | 2.00 | 38 | 12 | 1.42 | 27 | 3 |
1997 | 1 | 2.21 | 42 | 13 | 0.89 | 17 | 5 |
1998 | 1 | 2.37 | 45 | 14 | 1.00 | 19 | 2 |
1999 | 1 | 3.11 | 59 | 15 | 1.53 | 29 | 3 |
2000 | 1 | 2.58 | 49 | 15 | 1.00 | 19 | 4 |
2001 | 1 | 2.11 | 40 | 11 | 1.47 | 28 | 3 |
2002 | 1 | 2.21 | 42 | 16 | 1.16 | 22 | 4 |
2003 | 1 | 1.95 | 37 | 12 | 1.05 | 20 | 6 |
2004 | 1 | 1.63 | 31 | 12 | 0.74 | 14 | 4 |
2005 | 1 | 1.95 | 37 | 13 | 1.37 | 26 | 4 |
2006 | 1 | 2.42 | 46 | 15 | 0.79 | 15 | 3 |
2007 | 1 | 2.47 | 47 | 17 | 0.79 | 15 | 4 |
2008 | 1 | 2.26 | 43 | 16 | 0.58 | 11 | 3 |
2009 | 1 | 2.74 | 52 | 16 | 0.84 | 16 | 5 |
2010 | 1 | 2.58 | 49 | 18 | 1.32 | 25 | 4 |
2011 | 1 | 2.74 | 52 | 15 | 0.74 | 14 | 3 |
2012 | 1 | 2.37 | 45 | 16 | 1.26 | 24 | 2 |
2013 | 1 | 1.53 | 29 | 9 | 1.16 | 22 | 5 |
2014 | 1 | 2.16 | 41 | 14 | 1.16 | 22 | 5 |
2015 | 1 | 1.42 | 27 | 12 | 1.37 | 26 | 8 |